﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using olierFrm.DataBase.FrameWork.Plugin;

namespace olierFrm.DataBase.FrameWork.StdQuery
{
    public class SubQuery
    {
        public class SubQueryEntity
        {
            public string HintQueryName
            {
                get;
                set;
            }
            public string ParamName
            {
                get;
                set;
            }
            public string KeyFieldName
            {
                get;
                set;
            }
            public string ParamMatch
            {
                get;
                set;
            }
            public string HideFields
            {
                get;
                set;
            }
            public int DisplayType
            {
                get;
                set;
            }
            public int GroupByBox
            {
                get;
                set;
            }
            public int ShowFooter
            {
                get;
                set;
            }
            public int VisibleItem
            {
                get;
                set;
            }
        }
        private Dictionary<string, SubQuery.SubQueryEntity> _SciptObject = new Dictionary<string, SubQuery.SubQueryEntity>();
        public Dictionary<string, SubQuery.SubQueryEntity> SciptObject
        {
            get
            {
                return this._SciptObject;
            }
            set
            {
                this._SciptObject = value;
            }
        }
        public SubQuery(string subQuery)
        {
            Dictionary<string, Dictionary<string, string>> sqs = SmartINI.LoadIni(subQuery);
            foreach (KeyValuePair<string, Dictionary<string, string>> s in sqs)
            {
                SubQuery.SubQueryEntity sqe = new SubQuery.SubQueryEntity();
                sqe.HintQueryName = (s.Value.ContainsKey("HintQueryName") ? s.Value["HintQueryName"].ToString() : "");
                sqe.ParamName = (s.Value.ContainsKey("ParamName") ? s.Value["ParamName"].ToString() : "");
                sqe.ParamMatch = (s.Value.ContainsKey("ParamMatch") ? s.Value["ParamMatch"].ToString() : "");
                sqe.HideFields = (s.Value.ContainsKey("HideFields") ? s.Value["HideFields"].ToString() : "");
                sqe.DisplayType = (s.Value.ContainsKey("DisplayType") ? Convert.ToInt32(s.Value["DisplayType"]) : 0);
                sqe.GroupByBox = (s.Value.ContainsKey("GroupByBox") ? Convert.ToInt32(s.Value["GroupByBox"]) : 0);
                sqe.ShowFooter = (s.Value.ContainsKey("ShowFooter") ? Convert.ToInt32(s.Value["ShowFooter"]) : 0);
                sqe.VisibleItem = (s.Value.ContainsKey("VisibleItem") ? Convert.ToInt32(s.Value["VisibleItem"]) : 10);
                this._SciptObject.Add(s.Key, sqe);
            }
        }
        public SubQuery.SubQueryEntity GetSubQuery(string key)
        {
            return this._SciptObject[key];
        }
    }
}
